package com.lmqb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmqb.bean.LmUser;
import com.lmqb.bean.LogEmail;
import com.lmqb.bean.LogSms;
import com.lmqb.bean.LogWeixin;
import com.lmqb.bean.SysUser;
import com.lmqb.bean.SysUserLoginLog;
import com.lmqb.dao.LmUserMapper;
import com.lmqb.dao.LogEmailMapper;
import com.lmqb.dao.LogSmsMapper;
import com.lmqb.dao.LogWeixinMapper;
import com.lmqb.dao.SysUserMapper;
import com.lmqb.page.EmailLogPager;
import com.lmqb.page.PageTool;
import com.lmqb.page.SmsLogPager;
import com.lmqb.page.WeiXinLogPager;
import com.lmqb.service.LogService;
import com.lmqb.util.StrUtil;
@Service("logService")
public class LogServiceImpl implements LogService{

	@Autowired
	private LogEmailMapper logEmailDao;
	
	@Autowired
	private LogSmsMapper smsDao;
	
	@Autowired
	private LogWeixinMapper logWeiXinDao;
	
	@Autowired
	private LmUserMapper lmUserDao;
	
	/**
	 *@show  跳转到邮件发送日志页面
	 * 
	 *@param 
	 * 
	 * */
	public EmailLogPager selectEmailPager(EmailLogPager pagerModel) {
		List<LogEmail> list=logEmailDao.selectAll(pagerModel);
//		List<LmUser> userList=lmUserDao.selectAllUser();
		for(int i=0;i<list.size();i++){
			list.get(i).setAddTimeD(StrUtil.intToTime(list.get(i).getAddTime()));
			list.get(i).setSendTimeD(StrUtil.intToTime(list.get(i).getSendTime()));
//			for(int j=0;j<userList.size();j++){
//				if(list.get(i).getUserId()==userList.get(j).getUserId()){
//					list.get(i).setUserName(userList.get(j).getLoginMobile());
//					break;
//				}
//			}
		}
		pagerModel.setList(list);
		int count = logEmailDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}

	//@Override
	public SmsLogPager selectSmsPager(SmsLogPager pagerModel) {
		List<LogSms> list=smsDao.selectAll(pagerModel);
//		List<LmUser> userList=lmUserDao.selectAllUser();
		for(int i=0;i<list.size();i++){
			list.get(i).setAddTimeD(StrUtil.intToTime(list.get(i).getAddTime()));
			list.get(i).setSendTimeD(StrUtil.intToTime(list.get(i).getSendTime()));
			list.get(i).setExpectTimeD(StrUtil.intToTime(list.get(i).getExpectTime()));
//			for(int j=0;j<userList.size();j++){
//				if(list.get(i).getUserId()==userList.get(j).getUserId()){
//					list.get(i).setUserMobile(userList.get(j).getLoanMobile());
//					break;
//				}
//			}
		}
		pagerModel.setList(list);
		int count = smsDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}

	//@Override
	public WeiXinLogPager selectWeiXinPager(WeiXinLogPager pagerModel) {
		List<LogWeixin> list=logWeiXinDao.selectAll(pagerModel);
//		List<LmUser> userList=lmUserDao.selectAllUser();
		for(int i=0;i<list.size();i++){
			list.get(i).setAddTimeD(StrUtil.intToTime(list.get(i).getAddTime()));
			list.get(i).setSendTimeD(StrUtil.intToTime(list.get(i).getSendTime()));
			list.get(i).setExpectTimeD(StrUtil.intToTime(list.get(i).getExpectTime()));
//			for(int j=0;j<userList.size();j++){
//				if(list.get(i).getUserId()==userList.get(j).getUserId()){
//					list.get(i).setUserMobile(userList.get(j).getLoanMobile());
//					break;
//				}
//			}
		}
		pagerModel.setList(list);
		int count = logWeiXinDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}

}
